<template>
	<div>
		<el-input v-model="username" placeholder="请输入账号"></el-input>
		<el-input v-model="password" placeholder="请输入密码"></el-input>
		<el-button type="primary" @click="login">登录</el-button>
	</div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            username:'',
            password:'',
        }
    },
    methods: {
        login(){
            this.$http.post('/user/signin',{
                username:this.username,
                password:this.password,
            }).then(res => {
                if(res.errcode ==0){
                    this.$store.commit('setUser',res.data)
                    localStorage.serItem('token',res.data.token)

                    this.$http.get('/user/info').then(res =>{
                        if(res.errcode ==0){
                            this.$store.commit('setUser',res.data)
                        }else{
                            this.$router.push('/login')
                        }
                    })
                    this.$router.push('/')
                }
                //消息弹出显示
                else{
                    this.$message.error(res.errmsg)
                }
            })
        }
    },
}
	
</script>

<style lang=" "></style>
